<?php
require_once("../admin_config.inc.php");

class test
{
    private $table = null;
    
    function __construct()
    {
        // create a connection to the database
        $db = connect_db();
        
        $this->table = "test";
    }

    function addTest($uname)
    {
        $datetime = date('Y-m-d H:i:s');
        $username = mysql_real_escape_string($uname);
        $id = mt_rand();
        $data = array(  'test_id' => $id,
                        'uname' => $username,
                        'date_taken' => $datetime);
        $keys = implode("`,`",array_keys($data));
        $values = implode("','",$data);
        
        $add_query = vsprintf("insert into {$this->table}(`%s`) values('%s')",array($keys,$values));
        $add_res = mysql_query($add_query);
        
        return $add_res;
    }
    
    function delTest($testid)
    {
        $test_id = mysql_real_escape_string($testid);
        
        $del_query = "delete from {$this->table} where test_id = {$test_id}";
        $del_res = mysql_query($del_query);
        
        return $del_res;
    }
    
    function editTime($testid,$datetaken)
    {
        $test_id = mysql_real_escape_string($testid);
        $date_taken = mysql_real_escape_string($datetaken);
        
        $update_query = "update {$this->table} set date_taken='{$date_taken}' where test_id = {$test_id}";
        $update_res = mysql_query($update_query);
        
        return $update_res;
    }
}
?>
